from langchain_core.tools import tool


@tool
async def calculator(expression: str) -> str:
    """计算数学表达式"""
    print(f"函数被调用, 计算 {expression}")
    try:
        result = eval(expression)
        return str(result)
    except Exception as e:
        return f"错误: {e}"